//
//  SpeakTopView.m
//  YiXiProject
//
//  Created by iMac on 2019/7/26.
//  Copyright © 2019 iMac. All rights reserved.
//

#import "SpeakTopView.h"

@implementation SpeakTopView

-(UIButton *)leftSeapBtn
{
    if(!_leftSeapBtn)
    {
        _leftSeapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftSeapBtn.tag = 100;
        
        UIImageView *lefImg = [[UIImageView alloc]initWithFrame:CGRectMake(3, 3, 30, 30)];
        lefImg.image = [UIImage imageNamed:@"sepBack"];
        [_leftSeapBtn addSubview:lefImg];
        
        [_leftSeapBtn addTarget:self action:@selector(clickSpeakBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftSeapBtn;
}

-(UIImageView *)speakHeadImg
{
    if(!_speakHeadImg)
    {
        _speakHeadImg = [[UIImageView alloc] init];
        _speakHeadImg.image = [UIImage imageNamed:@"head"];
        _speakHeadImg.layer.cornerRadius = 25;
        _speakHeadImg.layer.masksToBounds = YES;
    }
    return _speakHeadImg;
}

-(UIButton *)rightSeapBtn
{
    if(!_rightSeapBtn)
    {
        _rightSeapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightSeapBtn.tag = 101;
        
        UIImageView *lefImg = [[UIImageView alloc]initWithFrame:CGRectMake(3, 3, 30, 30)];
        lefImg.image = [UIImage imageNamed:@"sepRightImg"];
        [_rightSeapBtn addSubview:lefImg];
        
        [_rightSeapBtn addTarget:self action:@selector(clickSpeakBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightSeapBtn;
}

-(UILabel *)nameL
{
    if(!_nameL)
    {
        _nameL = [[UILabel alloc] init];
        _nameL.text = @"Hello";
        _nameL.font = HeiTiFont(13);
        _nameL.textAlignment = NSTextAlignmentCenter;
    }
    return _nameL;
}


-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self addSubview:self.leftSeapBtn];
        [self addSubview:self.speakHeadImg];
        [self addSubview:self.rightSeapBtn];
        [self addSubview:self.nameL];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _leftSeapBtn.sd_layout.leftSpaceToView(self, 20).bottomSpaceToView(self, 40).widthIs(40).heightIs(40);
    _speakHeadImg.sd_layout.leftSpaceToView(self, SCREEN_WIDTH/2-25).bottomSpaceToView(self, 50).widthIs(50).heightIs(50);
    _rightSeapBtn.sd_layout.rightSpaceToView(self, 15).bottomSpaceToView(self, 40).widthIs(40).heightIs(40);
    _nameL.sd_layout.rightSpaceToView(self, SCREEN_WIDTH/2-70).bottomSpaceToView(self, 15).widthIs(140).topSpaceToView(_speakHeadImg, 2);
}

-(void)clickSpeakBtn:(UIButton *)butt
{
    if([_delegate respondsToSelector:@selector(clickSpeakButtonTag:)])
    {
        [_delegate clickSpeakButtonTag:butt.tag];
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
